package com.baigt.j8.lambda;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

/**
 * java.util.function.Supplier
 * Represents a supplier of results.
 * 表示提供一个返回结果(没有入参)
 * Supplier<T>
 *     T 要返回对象的类型
 */
public class _004SupplierDemo {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("Hello", "World");
        Supplier<Animal> animalSupplier=()->new Animal();
        System.out.println(animalSupplier.get().getName());
        Supplier<Animal> animalSupplier1= Animal::new;
        System.out.println(animalSupplier1.get().getName());
        List<Animal> animals=new ArrayList<>();
        Supplier<Animal> getInstance = Animal::getInstance;
        getInstance.get();
    }
}
class Animal{

    String name="ricky";
    int age;
    public static Animal getInstance(){
        return new Animal();
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

